<template>
	<view class="edit p-2" v-else>
		<view class="tip">{{tip}}</view>
		<u--input
		    :placeholder="placeholder"
		    border="surround"
		    v-model="text"
			:maxlength="length"
		></u--input>
		<view class="btn mt-3">
			<u-button type="primary" text="保存" shape="circle"
				@click="save()"
			></u-button>
		</view>
		<view class="btn mt-3">
			<u-button type="error" text="取消" shape="circle"
				@click="$emit('cancel')"
			></u-button>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'edit',
		props: {
			placeholder: {
				type: String,
				default: ''
			},
			tip: {
				type: String,
				default: ''
			},
			value: {
				type: String,
				default: ''
			},
			length: {
				type: Number,
				default: -1
			}
		},
		data() {
			return {
				text: ''
			}
		},
		methods: {
			save() {
				if(this.text == '') {
					this.$msg('用户名不能为空！');
				}else this.$emit('save', this.text);
			}
		}
	}
</script>

<style>
</style>